// import Dialog from '@vant/weapp/dialog/dialog';
//new Date(1230999938); 
const app = getApp()
Component({
  data: {
    alarm_show: false,
    alarm_time: app.globalData.alarm_time,
    alarm_info: app.globalData.alarm_info,
    alarm_user: app.globalData.alarm_user,
    devicename: app.globalData.devicename,
    duuid: app.globalData.duuid,
    uuid: app.globalData.uuid,
    imgsrc: ''
  },
  attached: function () {
    let that = this;
    ['uuid','duuid','alarm_show', 'alarm_time', 'devicename', 'alarm_info', 'alarm_user','imgsrc'].forEach(key => {
      // 监听全局变化
      app.setWatching(key, (v) => {
        that.setData({
          [key]: v
        });
      });
    })
  },
 
  
  methods: {
    // 这里是一个自定义方法
    onAlarmClose(e) {
      app.globalData.alarm_show = false
    },
    onAlarmConfirm(e) {
      var that = this
      // console.log(e)
      console.log("uuid", app.globalData.uuid) 
      console.log("phone", app.globalData.phone)
      console.log("devicename", app.globalData.devicename)
      console.log("msg alarm_info", this.data.alarm_info)
      app.globalData.alarm_show = false

      //this.initSocket();

      // if (app.globalData.alarm_info == "远程开锁请求")
      // {
      //     wx.navigateTo({
      //       url: '../msg_details/msg_details?id=2&uuid=' + app.globalData.uuid + '&alarm_time=' + alarm_time + '&timestamp=' + timestamp + '&alarm_info=' + alarm_info,
      //     })
      // }  globalData.timestamp
      // else
      if (this.data.alarm_info == "用户初始化")
      {
        wx.showToast({ title: '', icon: 'loading', duration: 10000 });
        setTimeout(function () {
          wx.hideToast();
          wx.reLaunch({
            url: '../index/index?uuid=' + that.data.uuid + "&phone=" + app.globalData.phone,
          })

        }, 1500)
       
    
      }
      else
      {
        wx.redirectTo({
          url: '../devmessage/devmessage?uuid=' + this.data.uuid + "&phone=" + app.globalData.phone + "&unlock=" + this.data.alarm_info + "&timestamp=" + app.globalData.timestamp + "&devicename=" + this.data.devicename ,
        })
      }
     

    },
  }
})